package com.hontech.bv.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.TextView
import com.hontech.bv.R

class NumberSensorView(ctx: Context, attrs: AttributeSet) : FrameLayout(ctx, attrs) {

    private val mTvName: TextView
    private val mTvVal: TextView

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_number_sensor, this)
        mTvName = view.findViewById(R.id.id_view_num_tv_name)
        mTvVal = view.findViewById(R.id.id_view_num_tv_val)

        val attr = ctx.obtainStyledAttributes(attrs, R.styleable.NumberSensorView)
        val name = attr.getText(R.styleable.NumberSensorView_num_name)
        mTvName.text = name
        attr.recycle()
    }

    fun set(value: Int) {
        mTvVal.text = "$value"
    }

    fun set(value: String) {
        mTvVal.text = value
    }
}

